<?php

namespace app\admin\controller;

use app\admin\model\Member;

use think\Request;

class Rechargerecord extends Base
{

    public function _initialize()
    {
        parent::_initialize();

        $defaultWhere = $this->getDefaultWhere();
        $defaultWhere['type'] = 1;
        $this->defaultWhere = $defaultWhere;
        $this->defaultOrder = 'create_date DESC';
    }

    public function index(){

        return parent::index();
    }

    /**
     * 处理列表数据
     */
    public function handleListData($data){
        foreach ($data as $item) {
            $item['record_money'] = $item['record_money'] / 100;
            $item['gift_money'] = $item['gift_money'] / 100;
            $memberInfo = Member::where('id', $item['member_id'])->find();
            if($memberInfo){
                $item['name'] = $memberInfo['name'];
                $item['account_number'] = $memberInfo['account_number'];
                $item['balance'] = $memberInfo['balance'] / 100;
            }
        }

        return $data;
    }

    /**
     * 筛选条件
     */
    public function getFilterWhere($request){
        $param = $request->param();
        $where = [];
        if(isset($param['account_number']) && $param['account_number']){
            $memberIds = Member::where(['name' => ['like', '%'.$param['account_number'].'%']])->column('id');
            $where['member_id'] = ['in', $memberIds];
        }

        return $where;
    }

}